// --------------------------------------------------------------------------------------------------------------------
// <copyright file="UcCodeColorize.cs" company="SmartPlan">
//   SmartPlan 2011
// </copyright>
// <summary>
//   Summary description for CodeColorize.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace DbDiff.WinClient.Forms.DbItems
{
	using System;
	using System.Drawing;
	using System.Windows.Forms;
	using ScintillaNet;

	/// <summary>
	/// The CodeColorize.
	/// </summary>
	public class UcCodeColorize : UserControl
	{
		#region Private Declaration

		/// <summary>
		/// The config.
		/// </summary>
		private readonly Scintilla config;

		/// <summary>
		/// The context menu 1.
		/// </summary>
		private ContextMenu contextMenu1;

		/// <summary>
		/// The menu item 2.
		/// </summary>
		private MenuItem menuItem2;

		/// <summary>
		/// The menu item 5.
		/// </summary>
		private MenuItem menuItem5;

		/// <summary>
		/// The mnu copy.
		/// </summary>
		private MenuItem mnuCopy;

		/// <summary>
		/// The mnu cut.
		/// </summary>
		private MenuItem mnuCut;

		/// <summary>
		/// The mnu delete.
		/// </summary>
		private MenuItem mnuDelete;

		/// <summary>
		/// The mnu paste.
		/// </summary>
		private MenuItem mnuPaste;

		/// <summary>
		/// The mnu redo.
		/// </summary>
		private MenuItem mnuRedo;

		/// <summary>
		/// The mnu select all.
		/// </summary>
		private MenuItem mnuSelectAll;

		/// <summary>
		/// The mnu undo.
		/// </summary>
		private MenuItem mnuUndo;

		/// <summary>
		/// The scintilla control 1.
		/// </summary>
		private Scintilla scintillaControl1;

		#endregion

		#region Properties

		/// <summary>
		/// The _copy paste enabled.
		/// </summary>
		private bool copyPasteEnabled;

		/// <summary>
		/// Gets or sets a value indicating whether CopyPasteEnabled.
		/// </summary>
		public bool CopyPasteEnabled
		{
			get { return this.copyPasteEnabled; }

			set
			{
				this.copyPasteEnabled = value;

				this.scintillaControl1.ContextMenu = this.copyPasteEnabled ? this.contextMenu1 : null;
			}
		}

		#endregion properties

		/// <summary>
		/// Initializes a new instance of the <see cref="UcCodeColorize"/> class.
		/// </summary>
		public UcCodeColorize()
		{
			// This call is required by the Windows.Forms Form Designer.
			this.InitializeComponent();

			// CopyPaste Functions Disabled by default
			this.CopyPasteEnabled = true;
		}

		/// <summary>
		/// The set text.
		/// </summary>
		/// <param name="text">
		/// The new text
		/// </param>
		public void SetText(string text)
		{
			this.ReadOnly(false);

			this.scintillaControl1.Text = text;

			this.ReadOnly(true);
		}

		/// <summary>
		/// The read only.
		/// </summary>
		/// <param name="readOnly">
		/// The is read only.
		/// </param>
		public void ReadOnly(bool readOnly)
		{
			this.scintillaControl1.IsReadOnly = readOnly;
		}

		/// <summary>
		/// The char added.
		/// </summary>
		/// <param name="sender">
		/// The p sender.
		/// </param>
		/// <param name="ch">
		/// The ch xxxxx
		/// </param>
		private void CharAdded(Scintilla sender, int ch)
		{
			// System.Diagnostics.Debugger.Break();
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">
		/// The disposing.
		/// </param>
		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
			}

			base.Dispose(disposing);
		}

		/// <summary>
		/// The context menu 1_ popup.
		/// </summary>
		/// <param name="sender">
		/// The sender.
		/// </param>
		/// <param name="e">
		/// The eventargs
		/// </param>
		private void ContextMenu1_Popup(object sender, EventArgs e)
		{
			this.mnuUndo.Enabled = this.scintillaControl1.UndoRedo.CanUndo;
			this.mnuRedo.Enabled = this.scintillaControl1.UndoRedo.CanRedo;
			this.mnuPaste.Enabled = this.scintillaControl1.Clipboard.CanPaste;
		}

		/// <summary>
		/// The mnu undo_ click.
		/// </summary>
		/// <param name="sender">
		/// The sender.
		/// </param>
		/// <param name="e">
		/// The eventargs
		/// </param>
		private void MnuUndo_Click(object sender, EventArgs e)
		{
			this.scintillaControl1.UndoRedo.Undo();
		}

		/// <summary>
		/// The mnu redo_ click.
		/// </summary>
		/// <param name="sender">
		/// The sender.
		/// </param>
		/// <param name="e">
		/// The eventargs
		/// </param>
		private void MnuRedo_Click(object sender, EventArgs e)
		{
			this.scintillaControl1.UndoRedo.Redo();
		}

		/// <summary>
		/// The mnu cut_ click.
		/// </summary>
		/// <param name="sender">
		/// The sender.
		/// </param>
		/// <param name="e">
		/// The eventargs
		/// </param>
		private void MnuCut_Click(object sender, EventArgs e)
		{
			//this.scintillaControl1.Clipboard.Cut();
		}

		/// <summary>
		/// The mnu copy_ click.
		/// </summary>
		/// <param name="sender">
		/// The sender.
		/// </param>
		/// <param name="e">
		/// The eventargs
		/// </param>
		private void MnuCopy_Click(object sender, EventArgs e)
		{
			this.scintillaControl1.Clipboard.Copy();
		}

		/// <summary>
		/// The mnu paste_ select.
		/// </summary>
		/// <param name="sender">
		/// The sender.
		/// </param>
		/// <param name="e">
		/// The eventargs
		/// </param>
		private void MnuPaste_Select(object sender, EventArgs e)
		{
			//this.scintillaControl1.Clipboard.Paste();
		}

		/// <summary>
		/// The mnu delete_ select.
		/// </summary>
		/// <param name="sender">
		/// The sender.
		/// </param>
		/// <param name="e">
		/// The eventargs
		/// </param>
		private void MnuDelete_Select(object sender, EventArgs e)
		{
		}

		/// <summary>
		/// The mnu select all_ select.
		/// </summary>
		/// <param name="sender">
		/// The sender.
		/// </param>
		/// <param name="e">
		/// The eventargs
		/// </param>
		private void MnuSelectAll_Select(object sender, EventArgs e)
		{
			this.scintillaControl1.Selection.SelectAll();
		}

		#region Component Designer generated code

		/// <summary> 
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.scintillaControl1 = new Scintilla();
			this.contextMenu1 = new System.Windows.Forms.ContextMenu();
			this.mnuUndo = new System.Windows.Forms.MenuItem();
			this.mnuRedo = new System.Windows.Forms.MenuItem();
			this.menuItem2 = new System.Windows.Forms.MenuItem();
			this.mnuCut = new System.Windows.Forms.MenuItem();
			this.mnuCopy = new System.Windows.Forms.MenuItem();
			this.mnuPaste = new System.Windows.Forms.MenuItem();
			this.mnuDelete = new System.Windows.Forms.MenuItem();
			this.menuItem5 = new System.Windows.Forms.MenuItem();
			this.mnuSelectAll = new System.Windows.Forms.MenuItem();
			this.SuspendLayout();
			// 
			// scintillaControl1
			// 
			this.scintillaControl1.Caret.CurrentLineBackgroundColor = Color.Silver;
			this.scintillaControl1.Caret.Position = 0;
			this.scintillaControl1.Caret.Style = CaretStyle.Line;
			this.scintillaControl1.Caret.HighlightCurrentLine = true;
			this.scintillaControl1.Caret.Width = 0;
			this.scintillaControl1.ContextMenu = this.contextMenu1;
			this.scintillaControl1.CurrentPos = 0;
			this.scintillaControl1.Dock = DockStyle.Fill;
			this.scintillaControl1.Indentation.IndentWidth = 0;
			this.scintillaControl1.IsReadOnly = false;
			this.scintillaControl1.Indentation.TabIndents = true;
			this.scintillaControl1.Location = new Point(0, 0);
			this.scintillaControl1.Margin = new Padding(0);
			this.scintillaControl1.Name = "scintillaControl1";
			this.scintillaControl1.Selection.Mode = ScintillaNet.SelectionMode.Lines;
			this.scintillaControl1.Size = new Size(704, 432);
			this.scintillaControl1.TabIndex = 0;
			this.scintillaControl1.Text = "scintillaControl1";
			this.scintillaControl1.Whitespace.Mode = WhitespaceMode.Invisible;
			this.scintillaControl1.Zoom = 0;
			this.scintillaControl1.ConfigurationManager.Language = "mssql";
			// 
			// contextMenu1
			// 
			this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.mnuUndo,
            this.mnuRedo,
            this.menuItem2,
            this.mnuCut,
            this.mnuCopy,
            this.mnuPaste,
            this.mnuDelete,
            this.menuItem5,
            this.mnuSelectAll});
			this.contextMenu1.Popup += new System.EventHandler(this.ContextMenu1_Popup);
			// 
			// mnuUndo
			// 
			this.mnuUndo.Index = 0;
			this.mnuUndo.Shortcut = System.Windows.Forms.Shortcut.CtrlZ;
			this.mnuUndo.Text = "&Undo";
			this.mnuUndo.Click += new System.EventHandler(this.MnuUndo_Click);
			// 
			// mnuRedo
			// 
			this.mnuRedo.Index = 1;
			this.mnuRedo.Text = "&Redo";
			this.mnuRedo.Click += new System.EventHandler(this.MnuRedo_Click);
			// 
			// menuItem2
			// 
			this.menuItem2.Index = 2;
			this.menuItem2.Text = "-";
			// 
			// mnuCut
			// 
			this.mnuCut.Index = 3;
			this.mnuCut.Shortcut = System.Windows.Forms.Shortcut.CtrlX;
			this.mnuCut.Text = "Cu&t";
			this.mnuCut.Click += new System.EventHandler(this.MnuCut_Click);
			// 
			// mnuCopy
			// 
			this.mnuCopy.Index = 4;
			this.mnuCopy.Shortcut = System.Windows.Forms.Shortcut.CtrlC;
			this.mnuCopy.Text = "Cop&y";
			this.mnuCopy.Click += new System.EventHandler(this.MnuCopy_Click);
			// 
			// mnuPaste
			// 
			this.mnuPaste.Index = 5;
			this.mnuPaste.Shortcut = System.Windows.Forms.Shortcut.CtrlV;
			this.mnuPaste.Text = "&Paste";
			this.mnuPaste.Click += new System.EventHandler(this.MnuPaste_Select);
			// 
			// mnuDelete
			// 
			this.mnuDelete.Index = 6;
			this.mnuDelete.Text = "&Delete";
			this.mnuDelete.Click += new System.EventHandler(this.MnuDelete_Select);
			// 
			// menuItem5
			// 
			this.menuItem5.Index = 7;
			this.menuItem5.Text = "-";
			// 
			// mnuSelectAll
			// 
			this.mnuSelectAll.Index = 8;
			this.mnuSelectAll.Shortcut = System.Windows.Forms.Shortcut.CtrlA;
			this.mnuSelectAll.Text = "Select &All";
			this.mnuSelectAll.Click += new System.EventHandler(this.MnuSelectAll_Select);
			// 
			// ucCodeColorize
			// 
			this.Controls.Add(this.scintillaControl1);
			this.Name = "UcCodeColorize";
			this.Size = new System.Drawing.Size(704, 432);
			this.ResumeLayout(false);
		}

		#endregion
	}
}